/*
 * @(#)DynamicResult.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.result.template;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import com.nhncorp.lucy.web.helper.ServletHelper;
import com.nhncorp.usf.core.config.runtime.ResultPageInfo;
import com.nhncorp.usf.core.result.helper.FreemarkerConfigFactory;
import com.nhncorp.usf.core.util.StringUtil;

import freemarker.template.Configuration;

/**
 * @author Web Platform Development Team
 */
public class DynamicResult extends AbstractTemplateResult {
    private static final long serialVersionUID = 6444301399443786944L;

    /**
     * @param resultPage ResultPageInfo
     * @param dataMap    Map
     * @throws Exception the Exception
     * @see com.nhncorp.usf.core.result.AbstractResult#execute(com.nhncorp.usf.core.config.runtime.ResultPageInfo, java.util.Map)
     */
    public void execute(ResultPageInfo resultPage, Map<String, Object> dataMap) throws Exception {
        Configuration configuration = FreemarkerConfigFactory.getConfiguration();
        HttpServletResponse response = ServletHelper.getResponse();
        response.setContentType(contentType + "; charset=" + getPageEncoding());

        setPageBufferSize(resultPage, response);

        String src = resultPage.getSrc();
        src = StringUtil.getNewSrc(src, dataMap);
        execute(resultPage,  dataMap, src, configuration, response);
    }
}
/*
 *
 *
 * 아래와 같이 run.xml 작성하면
 * key1, key2 의  값이 dataMap에 있는 값으로 대치됨.
 * BO의 result로 해당 값이 없으면 차선책으로 parameterMap에 있는 값을 사용하기에 테스트에 편리함.
 *
 * <action id="init">
*		<result>
*			<success>
*				<page type="template">
*					<property name="language">dynamic</property>
*					<property name="src">/WEB-INF/templates/${key1}/${key2}/uploadResult.ftl</property>
*				</page>
*			</success>
*		</result>
*		<services>
*	            <bo id="com.nhncorp.usf.example.bo.TestBO">
*	                <method id="getRandomKey" return-id="key1"/>
*	                <method id="getRandomKey" return-id="key2"/>
*	            </bo>
*		</services>
*	</action>
*/